/*
   BooyoPOSException.h
   
   Copyright (C) 2006 LinuxOne, Inc. <Republic of korea>

   This library is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1
   of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   Lessor General Public License for more details.

   You should have received a copy of the GNU Lessor General Public
   License along with this library; if not, write to the Free Software
   Foundation, inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

   Hyunjin Kim <mgc521@linuxone.co.kr>

   LinuxOne, Inc., hereby disclaims all copylight
   written by Hyunjin Kim, 20 December 2006
*/

#ifndef _BOOYO_POS_BOOYOPOSEXCEPTION_H_
#define _BOOYO_POS_BOOYOPOSEXCEPTION_H_

#include <exception>
#include <iostream>
#include <stdio.h>

namespace booyopos
{

class CByException : public std::exception
{
private:
	std::exception origException;
protected:
	int errCode;
	int errCodeExtended;
	char* description;
public:
	virtual const char* what()
	{
		return description;
	}

	CByException(int errCode)
	{
		char description[255];
		std::exception origException;

		sprintf(description, "%d", errCode);
		CByException(errCode, 0, description, origException);
	}

	CByException(int errCode, int errCodeExtended)
	{
		char description[255];
		std::exception origException;

		sprintf(description, "%d, %d", errCode, errCodeExtended);
		CByException(errCode, errCodeExtended, description, origException);
	}

	CByException(int errCode, char* description)
	{
		std::exception origException;
		CByException(errCode, 0, description, origException);
	}

	CByException(int errCode, int errCodeExtended, char* description)
	{
		CByException(errCode, errCodeExtended, description, origException);
	}

	CByException(int errCode, char* description, std::exception origException)
	{
		CByException(errCode, 0, description, origException);
	}

	CByException(int errCode, int errCodeExtended, char* description, std::exception origException)
	{
		CByException::errCode = errCode;
		CByException::errCodeExtended = errCodeExtended;
		CByException::description = description;
		CByException::origException = origException;

		//std::cout << what() << std::endl;
	}

	virtual ~CByException() throw ()
	{
	}

	int	GetErrorCode() const
	{
		return errCode;
	}

	int GetErrorCodeExtended() const
	{
		return errCodeExtended;
	}

	std::exception GetOrigException() const
	{
		return origException;
	}
};

} // namespace booyopos

#endif // _BOOYO_POS_BOOYOPOSEXCEPTION_H_
